//
//  Base64.m
//  Air
//
//  Created by dongguozheng on 2016/12/15.
//  Copyright © 2016年 董国政. All rights reserved.
//

#import "Base64.h"

@implementation Base64
-(NSString *)getBase64With:(NSString *)str
{
    NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
    
    NSString *base64String = [data base64EncodedStringWithOptions:0];
    
    return base64String;
}
#pragma - 因为Base64编码中包含有+,/,=这些不安全的URL字符串，所以要进行换字符
-(NSString*)safeUrlBase64Encode:(NSData*)data
{
    // '+' -> '-'
    // '/' -> '_'
    // '=' -> ''
    NSString * base64Str = [GTMBase64 stringByEncodingData:data];
    NSMutableString * safeBase64Str = [[NSMutableString alloc]initWithString:base64Str];
    safeBase64Str = (NSMutableString * )[safeBase64Str stringByReplacingOccurrencesOfString:@"+" withString:@"-"];
    safeBase64Str = (NSMutableString * )[safeBase64Str stringByReplacingOccurrencesOfString:@"/" withString:@"_"];
    safeBase64Str = (NSMutableString * )[safeBase64Str stringByReplacingOccurrencesOfString:@"=" withString:@""];

    return safeBase64Str;
}

@end
